package remove_element

import "fmt"

func RemoveElement (nums []int, val int) int {
	Loop:
	for i, num := range nums {
		if num == val && i < len(nums) {
			nums[i] = nums[len(nums)-1]
			nums = nums[:len(nums)-1]
			goto  Loop
		}
	}
	fmt.Println(nums)
	return len(nums)
}

func RemoveElement2 (nums []int, val int) int {
	i := 0
	for _, num := range nums {
		if num != val {
			nums[i] = num
			i++
		}
	}
	nums = nums[:i]
	fmt.Println(nums)
	return i
}
